package com.lpc.android.abc.main.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.lpc.android.abc.R;
import com.lpc.android.abc.base.base.BaseApplication;
import com.lpc.android.abc.base.bean.WareDetails;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WaresListAdatper extends RecyclerView.Adapter<WaresListAdatper.ViewHolder> {

    private final List<WareDetails> mList;

    RequestManager glide;


    public WaresListAdatper(Activity Activity, List<WareDetails> list) {
        this.mList = list;

        glide = Glide.with(Activity).setDefaultRequestOptions(BaseApplication.getAppComponent()
                .requestOptions());
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate
                (R.layout.adapter_wareslist, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        WareDetails wareDetails = mList.get(position);

        glide.load(wareDetails.getImgUrl()).into(holder.draweView);
        holder.textTitle.setText(wareDetails.getName());
        holder.textPrice.setText(String.valueOf(wareDetails.getPrice()));
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.text_title)
        TextView textTitle;

        @BindView(R.id.text_price)
        TextView textPrice;

        @BindView(R.id.drawee_view)
        ImageView draweView;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
